package redis

import (
	"fmt"
	"github.com/go-redis/redis"
	"usershop/good_srv/appconfig"
)

var RedClient *redis.Client

func InitRedis() {
	addr := appconfig.AppData.RedisConfig

	mah := fmt.Sprintf("%s:%d", addr.Head, addr.Pore)
	fmt.Println(mah)
	RedClient = redis.NewClient(&redis.Options{
		Addr:     mah,
		Password: "", // no password set
		DB:       0,  // use default DB
	})

	_, err := RedClient.Ping().Result()
	// Output: PONG <nil>

	if err != nil {
		fmt.Println("redis链接失败")
		return
	} else {
		fmt.Println("redis链接成功")
	}

}
